<div class="page-header">
	<ul id="table-tab" class="nav nav-tabs" role="tablist">
		<li role="presentation" class="active"><a href="#assets-tab"
			aria-controls="assets-tab" role="tab" data-toggle="tab">资产管理</a>
		</li>
	</ul>
</div>
<div class="tab-content">
	<div id="assets-tab" class="tab-pane active" role="tabpanel">
		<div class="row">
            <!--搜索域-->
            <div class="col-xs-12">
            	<div class="search-area">
            		<form id="table-assets-search" class="form-inline">
                        <div class="form-group">
                            <label for="assets.name">资产名称：</label>
                            <input type="text" class="form-control input-sm" id="assets-name" name="assets.name" value="" placeholder="按名称搜索">
                            <label for="assets.sub_name">所属专题：</label>
                            <input type="text" class="form-control input-sm" id="assets-sub-name" name="assets.sub_name" value="" placeholder="按专题名称搜索">
                            <!-- 浏览器bug，当form中存在单个input时，敲击enter键，会导致form提交，更改url。加入下面input解决此bug -->
                            <input style="display: none;"/>
                        </div>
	                    <button id="btn-assets-search" type="button" class="btn btn-info btn-sm no-border">
	                    	<i class="ace-icon fa fa-search bigger-110"></i>查询
	                    </button>
	                    <div class="form-group pull-right">
                    		<span>查询方式：</span>
                           	<label class="radio-inline">
                           		<input type="radio" name="searchType" value="1" checked="checked"/>精确
                           	</label>
                           	<label class="radio-inline">
                           		<input type="radio" name="searchType" value="0"/>模糊
                           	</label>
                        </div>
                    </form>
                </div>
            </div>
        </div>
		<!-- 数据表格 -->
        <div class="row">
            <div class="col-xs-12">
            	<div id="table-assets-toolbar">
            		<div class="btn-group btn-group-sm">
	                    <button id="addAssets" class="btn btn-info btn-sm no-border" 
	                    onclick="goAdd('新增资产', 'mnui/sub/assets/add', 'table-assets');">
	                        <i class="ace-icon fa fa-plus bigger-110"></i>新增
	                    </button>
	                    <button id="editAssets" class="btn btn-success btn-sm no-border"
	                    onclick="goUpdate('编辑资产', 'mnui/sub/assets/edit', 'table-assets');">
	                        <i class="ace-icon fa fa-pencil-square-o bigger-110"></i>编辑
	                    </button>
	                    <button id="delAssets" class="btn btn-danger btn-sm no-border"
	                    onclick="doDels('mnui/sub/assets/deletes', 'table-assets');">
	                        <i class="ace-icon fa fa-trash-o bigger-110"></i>删除
	                    </button>
	                    <button id="enable" class="btn btn-primary btn-sm no-border"
	                    onclick="enable('0');">
	                        <i class="ace-icon fa fa-check-square-o bigger-110"></i>启用
	                    </button>
	                    <button id="disable" class="btn btn-warning btn-sm no-border"
	                    onclick="enable('1');">
	                        <i class="ace-icon fa fa-square-o bigger-110"></i>停用
	                    </button>
                    </div>
                </div>
            	<table id="table-assets" 
            			data-toolbar="#table-assets-toolbar" 
            			data-sort-name="name" 
            			data-sort-order="asc"
            			data-show-columns="true"
            			data-id-field="uuid">
            		 <thead>
                        <tr>
                            <th data-field="state" data-checkbox="true"></th>
                            <th data-field="name" data-align="left" data-sortable="true">名称</th>
                            <th data-field="img_url" data-align="left" data-sortable="false">缩略图url</th>
                            <th data-field="focus_img_url" data-align="left" data-sortable="false">焦点图url</th>
                            <th data-field="sub_name" data-align="left" data-sortable="false">所属专题</th>
                            <th data-width="500" data-field="url" data-align="left" data-sortable="false">地址</th>
                            <th data-width="80" data-field="type" data-align="center" data-sortable="false" data-formatter="enableF">启用状态</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
	</div>
</div>

<script type="text/javascript">
	//对启用/停用 一列进行整理
	function enableF(value, row, index) {
		var val = parseInt(value)
		switch (val) {
		case 0:
			return "<font style=\"color:blue;\">已启用</font>";
		case 1: 
			return "<font style=\"color:red;\">已停用</font>";
		default:
			return val;
		}
	}
	//ajax设置批量启用/停用
	function enable(type) {
		var selections = $('#table-assets').bootstrapTable("getSelections");
		if (selections !== undefined && selections !== null) {
			if (selections.length > 0) {
				var ids = "";
				for (var i = 0; i < selections.length; i++) {
					ids += selections[i].uuid;
					if (i < selections.length - 1) {
						ids += ",";
					}
				}

				var _msg = "";
				if(type == '0'){
					_msg = "您确定要启用当前选中的数据记录吗?";
				}
				if(type == '1'){
					_msg = "您确定要停用当前选中的数据记录吗?";
				}
				var isOk = confirm(_msg);
				var params = {};
				params['ids'] = ids;
				params['type'] = type;
				if (isOk) {
					$.ajax({
						type : "POST",
						url : "mnui/sub/assets/enableAJax",
						data : params,
						success : function(data) {
							if (data.status == "OK") {
								$("#table-assets").bootstrapTable('refresh');
								TipMsg.success(data.message, 0);
							} else {
								TipMsg.error(data.message, 0);
							}
						}
					});
				}
			} else {
				TipMsg.error("请至少选择一条数据记录.", 0);
			}
		} else {
			TipMsg.error("没有可操作的数据记录.", 0);
		}
	}
	$(document).ready(
			function() {
				initTableList('table-assets', 'mnui/sub/assets/dataGrid',
						'table-assets-search', 'btn-assets-search');
			});
</script>
